﻿using System;
using System.Collections;
using FX.CC.Andon.Entity.BasicDataManage;
using FX.CC.Andon.Service.BasicDataManage;
using FX.CC.Andon.Utility.Json;

namespace FX.CC.Andon.Business.BasicDataManage
{
    public class LineBusiness
    {
        private readonly LineService _dal = new LineService();

        public string GetLineList()
        {
            return JsonHelper.Encode(_dal.GetLineList());
        }

        public string GetLineList(LineQcEntity qcmodel)
        {
            var total = _dal.GetLineCount(qcmodel);
            var list = _dal.GetLineList(qcmodel);
            return JsonHelper.Encode(total, list);
        }

        public bool AddLine(string data)
        {
            var model = new LineEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.LineID = Guid.NewGuid();
                model.LineCode = row["LineCode"].ToString();
                model.LineName = row["LineName"].ToString();
                model.WSID = new Guid(row["WSID"].ToString());
            }
            return _dal.AddLine(model);
        }

        public bool ModifyLine(string data)
        {
            var model = new LineEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.LineID = new Guid(row["LineID"].ToString());
                model.LineCode = row["LineCode"].ToString();
                model.LineName = row["LineName"].ToString();
                model.WSID = new Guid(row["WSID"].ToString());
            }
            return _dal.ModifyLine(model);
        }

        public int CheckLineByCode(string ceDeviceCode)
        {
            return _dal.CheckLineByCode(ceDeviceCode);
        }

        public string GetLineInfo(string id)
        {
            return JsonHelper.Encode(_dal.GetLineInfo(id));
        }

        public bool RemoveLine(string id)
        {
            return _dal.RemoveLine(id);
        }
    }
}
